package cookie;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * 演示 Cookie 的 MaxAge 属性
 */
public class MaxAge extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //设置cookie最长保存60*5秒
        Cookie cookie1 = new Cookie("thanZero", "thanZero");
        cookie1.setMaxAge(60*5);

        //设置cookie会话结束之后删除
        Cookie cookie2 = new Cookie("lessZero", "lessZero");
        cookie2.setMaxAge(-1);

        //设置cookie会被立即删除
        Cookie cookie3 = new Cookie("equalsZero", "equalsZero");
        cookie3.setMaxAge(0);

        resp.addCookie(cookie1);
        resp.addCookie(cookie2);
        resp.addCookie(cookie3);
    }
}
